package servlet;

import java.io.IOException;

//import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bminfo.migle.parser.PointMut;
//import org.codehaus.xfire.XFireFactory;
//import org.codehaus.xfire.client.XFireProxyFactory;
//import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class MutationServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public MutationServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String folderName = request.getSession().getAttribute("folderName").toString();
		String site = request.getParameter("site");

		String filetype = request.getSession().getAttribute("filetype").toString();
		
		String start = Integer.valueOf(Integer.parseInt(site) - 10).toString();
		String end = Integer.valueOf(Integer.parseInt(site) + 10).toString();
		
		request.getSession().setAttribute("site", site);
		
//		org.codehaus.xfire.service.Service srvcModel = new ObjectServiceFactory().create(IMoopsServer.class);
//		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
//		String moopsServiceURL = "http://" + request.getServerName().toString() + ":"
//		+ request.getServerPort() + "/miGLE/services/MoopsServer";
//		IMoopsServer srvc = (IMoopsServer)factory.create(srvcModel, moopsServiceURL);
		
		System.out.println(start);
		System.out.println(end);
        
        PointMut pm = new PointMut();
        
        String miGLE_home = request.getSession().getAttribute("miGLE_home").toString();
		
		folderName = request.getSession().getAttribute("folderName").toString();
			
		pm.setPointMutPath(miGLE_home, folderName);
		pm.pointMut(Integer.parseInt(site), "", filetype, "", "");
			
		response.sendRedirect("../miranda.jsp");
		
//		pm.setPointMutPath(miGLE_home, folderName);
//		pm.pointMut(start, end);
//		
//		pm.pointMut(Integer.parseInt(site), iupac_char, filetype, 
//				request.getSession().getAttribute("indel").toString(),
//				request.getSession().getAttribute("indel_string").toString());
		
//		System.out.println("Foldername in MutationServlet is: " + folderName);
		

		
//        RequestDispatcher rd = request.getRequestDispatcher("../miranda.jsp");   
//        rd.forward(request, response); 
        

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}
}
